package com.xiao.blecontrol;

import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;

/**
 * @Author xiaoxiaoping
 * @Date 2019/9/23
 */
public class SeekBarUtil {
    public static void sub(SeekBar seekBar, Integer step, Integer minValue, TextView textView,Integer type){
        Log.i("SeekBarUtil",minValue.toString());
        Integer orignValue = 0;
        if(1==type) {
            orignValue=seekBar.getProgress() + 80;
        }else{
            orignValue = seekBar.getProgress();
        }
        Log.i("SeekBarUtil","初始值："+orignValue.toString());
        Integer targetValue = orignValue - step;
        if(1==type) {
            if (targetValue < 80) {
                targetValue = minValue;
            }
        }else{
            if(targetValue <0){
                targetValue = minValue;
            }

        }


        if(1==type) {
            float newValue = (float)targetValue/100;
            textView.setText(String.valueOf(newValue));
            seekBar.setProgress(targetValue-80);
        }else{
            textView.setText(targetValue.toString());
            seekBar.setProgress(targetValue);
        }
    }
    public static void plus(SeekBar seekBar,Integer step,TextView textView,Integer type){
        Log.i("SeekBarUtil", String.valueOf(seekBar.getMax()));

        Integer maxValue = 0;
        if(1==type){
            maxValue = seekBar.getMax()+80;
        }else{
            maxValue = seekBar.getMax();
        }
        Integer orignValue =0;
        if(1==type) {
            orignValue=seekBar.getProgress() + 80;
        }else{
            orignValue = seekBar.getProgress();
        }
        Log.i("SeekBarUtil", String.valueOf(orignValue));
        Integer targetValue = orignValue+step;
        Log.i("SeekBarUtil", String.valueOf(targetValue));
        if(targetValue>seekBar.getMax()+80){
            targetValue = maxValue;
        }


        if(1==type) {
            float newValue = (float)targetValue/100;
            Log.i("SeekBarUtil","目标值："+newValue);
            textView.setText(String.valueOf(newValue));
            seekBar.setProgress(targetValue-80);
        }else{
            textView.setText(targetValue.toString());
            seekBar.setProgress(targetValue);
        }
    }
}
